home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Demos / Extend 3.0 Demo / Demo Libraries / Demo Custom Blocks Lib / Demo Custom Blocks Lib.rsrc / MODL_1971_Planet Plotter < prev    next >
Encoding:
Text File  |  1994-06-22  |  4.3 KB  |  236 lines

  1. integer    PCon1, PCon2, PCon3, PCon4;
  2. real    planet1[], planet2[], planet3[], planet4[];
  3. integer    half[4], hidden[4];
  4.  
  5. constant    fieldSize    is 200;
  6.  
  7. constant    xLowBound    is 0;
  8. constant     xHiBound    is 200;
  9. constant    yLowBound    is 0;
  10. constant    yHiBound    is 200;
  11.  
  12. constant    earth        is "Earth";
  13. constant    mars        is "Mars";
  14. constant    venus        is "Venus";
  15. constant    moon        is "Moon";
  16. constant    sun            is "Sun";
  17.  
  18. **     Planet Plotter block
  19. **    Copyright © 1993 by Imagine That, Inc.
  20. **    All rights reserved.
  21. **        J. Steven Lamperti 3/10/93
  22. **            modified
  23. **
  24.  
  25. // Planetary array elements
  26. //
  27. //  planet[0] = mass;
  28. //  planet[1] = x;
  29. //  planet[2] = y;
  30. //  planet[3] = planetID;
  31. //  planet[4] = density;
  32.  
  33.  
  34. procedure makePicture(integer obj, integer ID)
  35. {
  36.     if (ID == 1)
  37.         AnimationPicture(obj, earth, TRUE);
  38.     else if (ID == 2)
  39.         AnimationPicture(obj, mars, TRUE);
  40.     else if (ID == 3)
  41.         AnimationPicture(obj, venus, TRUE);
  42.     else if (ID == 4)
  43.         AnimationPicture(obj, moon, TRUE);
  44.     else if (ID == 5)
  45.         AnimationPicture(obj, sun, TRUE);
  46.     else 
  47.         AnimationPicture(obj, moon, TRUE);
  48. }
  49.  
  50.  
  51. procedure stretchPicture(integer obj, real mass, real density)
  52. {
  53.     integer size;
  54.     real    ratio;
  55.  
  56.     ratio   = mass/density;
  57.     size     = (fieldSize * ratio) / (maxX - minX);
  58.     size     = size + size * 0.20;  // 20% bigger for visual collisions
  59.  
  60.     if (size > 60)
  61.         size = 60;
  62.  
  63.     if (size < 2)
  64.         size = 2;
  65.  
  66.     AnimationStretchTo(obj, 0, 0, size, size, FALSE);
  67.     half[obj-1] = size/2;
  68. }
  69.  
  70.  
  71. procedure draw(integer useLast)
  72. {
  73.     real    x1, y1, x2, y2, x3, y3, x4, y4;
  74.  
  75.     if (pCon1)
  76.         {
  77.         if (!useLast)
  78.             {
  79.             GetPassedArray(planet1In, planet1);
  80.             if (currentStep == 0)
  81.                 {
  82.                 stretchPicture(1, planet1[0], planet1[4]);
  83.                 makePicture(1, planet1[3]);
  84.                 }
  85.             }
  86.  
  87.         x1 = (planet1[1] - minX) / (maxX - minX) * fieldSize;
  88.         y1 = fieldSize + (minY - planet1[2]) / (maxY - minY) * fieldSize;
  89.         if (x1 < xLowBound)
  90.             {
  91.             AnimationHide(1, FALSE);
  92.             Hidden[0] = 1;
  93.             }
  94.         else
  95.             {    
  96.             AnimationMoveTo(1, x1 - half[0], y1 - half[0], FALSE);
  97.             if (Hidden[0] || useLast)
  98.                 AnimationShow(1);
  99.             Hidden[0] = 0;
  100.             }
  101.         }
  102.  
  103.     if (pCon2)
  104.         {
  105.         if (!useLast)
  106.             {
  107.             GetPassedArray(planet2In, planet2);
  108.             if (currentStep == 0)
  109.                 {
  110.                 stretchPicture(2, planet2[0], planet2[4]);
  111.                 makePicture(2, planet2[3]);
  112.                 }
  113.             }
  114.  
  115.         x2 = (planet2[1] - minX) / (maxX - minX) * fieldSize;
  116.         y2 = fieldSize + (minY - planet2[2]) / (maxY - minY) * fieldSize;
  117.         if (x2 < xLowBound)
  118.             {
  119.             AnimationHide(2, FALSE);
  120.             Hidden[1] = 1;
  121.             }
  122.         else
  123.             {
  124.             AnimationMoveTo(2, x2 - half[1], y2 - half[1], FALSE);
  125.             if (Hidden[1] || useLast)
  126.                 AnimationShow(2);
  127.             Hidden[1] = 0;
  128.             }
  129.         }
  130.  
  131.     if (pCon3)
  132.         {
  133.         if (!useLast)
  134.             {
  135.             GetPassedArray(planet3In, planet3);
  136.             if (currentStep == 0)
  137.                 {
  138.                 stretchPicture(3, planet3[0], planet3[4]);
  139.                 makePicture(3, planet3[3]);
  140.                 }
  141.             }
  142.  
  143.         x3 = (planet3[1] - minX) / (maxX - minX) * fieldSize;
  144.         y3 = fieldSize + (minY - planet3[2]) / (maxY - minY) * fieldSize;
  145.         if (x3 < xLowBound)
  146.             {
  147.             AnimationHide(3, FALSE);
  148.             Hidden[2] = 1;
  149.             }
  150.         else
  151.             {
  152.             AnimationMoveTo(3, x3 - half[2], y3 - half[2], FALSE);
  153.             if (Hidden[2] || useLast)
  154.                 AnimationShow(3);
  155.             Hidden[2] = 0;
  156.             }
  157.         }
  158.         
  159.     if (pCon4)
  160.         {
  161.         if (!useLast)
  162.             {
  163.             GetPassedArray(planet4In, planet4);
  164.             if (currentStep == 0)
  165.                 {
  166.                 stretchPicture(4, planet4[0], planet4[4]);
  167.                 makePicture(4, planet4[3]);
  168.                 }
  169.             }
  170.  
  171.         x4 = (planet4[1] - minX) / (maxX - minX) * fieldSize;
  172.         y4 = fieldSize + (minY - planet4[2]) / (maxY - minY) * fieldSize;
  173.         if (x4 < xLowBound)
  174.             {
  175.             AnimationHide(4, FALSE);
  176.             Hidden[3] = 1;
  177.             }
  178.         else
  179.             {
  180.             AnimationMoveTo(4, x4 - half[3], y4 - half[3], FALSE);
  181.             if (Hidden[3] || useLast)
  182.                 AnimationShow(4);
  183.             Hidden[3] = 0;
  184.             }
  185.         }
  186. }
  187.  
  188.  
  189.  
  190. // This message occurs for each step in the simulation.
  191. on simulate
  192. {
  193.     if (animationOn)
  194.         draw(FALSE);
  195. }
  196.  
  197.  
  198. on EndSim
  199. {
  200.     if (animationOn)
  201.         draw(TRUE);
  202. }
  203.  
  204.  
  205. // If the dialog data is inconsistent for simulation, abort.
  206. on checkdata
  207. {
  208.     integer i;
  209.  
  210.     PCon1 = planet1In;
  211.     PCon2 = planet2In;
  212.     PCon3 = planet3In;
  213.     PCon4 = planet4In;
  214.     
  215.     AnimationHide(1, TRUE);
  216.     AnimationHide(2, TRUE);
  217.     AnimationHide(3, TRUE);
  218.     AnimationHide(4, TRUE);
  219.     
  220.     for(i = 0; i < 4; i++)
  221.         hidden[i] = 1;
  222.         
  223.     if (maxX - minX != maxY - minY)
  224.         Usererror("It is reccommended that you keep the plotters X dimension area equal to the plotters Y dimension area.");
  225. }
  226.  
  227.  
  228.  
  229. on createBlock
  230. {
  231.     minX = -50.0;
  232.     minY = -50.0;
  233.     maxX = 50.0;
  234.     maxY = 50.0;
  235. }
  236.